package tedu.study.Day05_2;

import java.util.Random;
import java.util.Scanner;

/**
 * 根据返回值void,修改后，目前停留在error状态
 */
public class Addition {
    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        int maxNum = 100;//算数的最大值
        String[] operators ={"+","-","*","/","%"};
        Random random = new Random();
        int sumScore = 0;//总分
        int score = 10;//每题的得分
        for(int i=1;i<=10;i++){
            //出题
            int num1 = (int)(Math.random()*maxNum);
            int num2 = (int)(Math.random()*maxNum);
            int index = random.nextInt(operators.length);
            /**
             * 无返回，会无法改变调用方的具体值，导致方法走完后，result仍=-10000
             */
            int result = -10000;
            getResult(num1,num2,index,result);
            System.out.println("("+i+")"+num1+operators[index]+num2+"=?");
            //答题
            System.out.println("请计算：");
            int answer = scan.nextInt();
            //判题
            if(answer == result){
                sumScore += score;
                System.out.println("计算正确！");
            }else{
                System.out.println("很遗憾错了。");
            }
        }
        System.out.println("总分为："+sumScore);

    }
    public static void getResult(int num1,int num2,int index,int result){
        switch (index){
            case 0:
                result = num1 + num2;
                break;
            case 1:
                result = num1 - num2;
                break;
            case 2:
                result = num1 * num2;
                break;
            case 3:
                result = num1 / num2;
                break;
            case 4:
                result = num1 % num2;
                break;
            default:
                result = -10000;
        }
    }

    /*int result = getResult(num1,num2,index);
    public static int getResult(int num1,int num2,int index){
        switch (index){
            case 0:
                return num1 + num2;
            case 1:
                return num1 - num2;
            case 2:
                return num1 * num2;
            case 3:
                return num1 / num2;
            case 4:
                return num1 % num2;
            default:
                return -10000;
        }
    }*/
}
